﻿namespace MTPAutoBackup;

public class FileUtils
{
    private static readonly string[] SizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB" };

    public static string ByteCountToDisplaySize(ulong byteCount)
    {
        if (byteCount == 0) return "0 B";

        int i = 0;
        decimal size = byteCount;

        // 循环以找到合适的单位
        while (size >= 1024 && i < SizeSuffixes.Length - 1)
        {
            size /= 1024;
            i++;
        }

        // 返回带单位的格式化字符串
        return $"{size:n1} {SizeSuffixes[i]}";
    }
}